package org.demo.controller;


import javax.servlet.http.HttpServletRequest;

import org.demo.dao.model.UserInfo;
import org.demo.service.user.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("user")
public class UserInfoController {
	
	@Autowired
	private UserInfoService userInfoService; 

	@RequestMapping("init")
	public String init(HttpServletRequest request){
//		UserInfo userInfo = userInfoService.selectByPrimaryKey(1);
//		System.out.println(JSON.toJSONString(userInfo));
		request.setAttribute("list", userInfoService.selectAll());
		return "user/init";
	}
	
	@RequestMapping("save")
	public String save(UserInfo userInfo){
		userInfoService.insertSelective(userInfo);
		return "redirect:/user/init";
	}
	
	@RequestMapping(value="del/{id}")
	public String del(@PathVariable Integer id){
		userInfoService.deleteByPrimaryKey(id);
		return "redirect:/user/init";
	}
	
}
